<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>事件的触发</title>
</head>
<body>
      <input type="text" name="chana" value="用户名" id="box">
        <script>

//             function foo() {
//                 if (onfocus){
//                     box.value= '';
//             }else if(onblur) {
//                     box.value = '用户名';
//                 }
//             }

             function doSth(){
                 if (document.getElementById('box').value=='用户名'){
                     document.getElementById('box').value= '';
                 }

             }
             function doSth2() {
                 if (document.getElementById('box').value == '') {
                     document.getElementById('box').value = '用户名';
                 }
             }
            document.getElementById('box').onfocus = doSth;
            document.getElementById('box').onblur = doSth2;





        </script>
        
</body>
</html>
onfocus  聚焦事件；得到焦点
onblur 失去焦点事件；元素失去焦点时
